package com.sinoglobal.sinostore.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import com.sinoglobal.sinostore.SinoStore;

//package cn.itkt.travelsky.service.parse;
//
//import java.io.IOException;
//import java.io.InputStream;
//
//import cn.itkt.travelsky.activity.ItktApplication;
//import cn.itkt.travelsky.utils.TextUtil;
//
public class TestJson {
	//
	private static String textToJson(String fileName) {
		try {
			InputStream is = SinoStore.context.getAssets().open(fileName);
			String json = inputStreamToString(is);
			return json;
		} catch (IOException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * 
	* @author LK
	* @methods getInvoice 
	* @description 描述信息 获取发票信息
	* @date 2015-1-21 下午12:07:59
	* @return 参数说明
	 */
	public static String getInvoice(){
		return textToJson("invoice");
	}

	/**
	 * 将输入流解析为String
	 * @param is
	 * @return
	 * @throws Exception
	 */
	public static String inputStreamToString(InputStream is)throws Exception {
		BufferedReader reader = new BufferedReader(new InputStreamReader(is,"UTF-8"));
		StringBuilder sb = new StringBuilder();
		String line = null;
		try {
			while ((line = reader.readLine()) != null) {
				sb.append(line);
				line=null;
			}
		} finally {
			try {
				if(reader!=null){
					reader.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		line=sb.toString();
		sb=null;
		return line;
	}
}
